package com.codingchili.logging.model;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Robin Duda
 */
public class Counters {
    private Map<String, Integer> classes = new HashMap<>();
    private Map<String, Integer> damage = new HashMap<>();
    private int characters = 0;
    private int despawn = 0;

    public Counters copy() {
        var counters = new Counters();
        counters.characters = characters;
        counters.despawn = despawn;
        counters.classes.putAll(classes);
        counters.damage.putAll(damage);
        return counters;
    }

    /**
     * Increases the created characters counter and modifies the class distribution.
     * @param className the name of the class to record.
     */
    public void characterCreated(String className) {
        this.characters++;
        classes.computeIfPresent(className, (key, value) -> value + 1);
        classes.putIfAbsent(className, 1);
    }

    public void despawn() {
        despawn++;
    }

    public void damage(String type, int count) {
        damage.computeIfPresent(type, (key, value) -> value + count);
        damage.putIfAbsent(type, count);
    }

    private void created(String className) {
        classes.computeIfPresent(className, (key, value) -> value + 1);
        classes.putIfAbsent(className, 1);
    }

    public Map<String, Integer> getClasses() {
        return classes;
    }

    public void setClasses(Map<String, Integer> classes) {
        this.classes = classes;
    }

    public int getCharacters() {
        return characters;
    }

    public void setCharacters(int characters) {
        this.characters = characters;
    }

    public Map<String, Integer> getDamage() {
        return damage;
    }

    public void setDamage(Map<String, Integer> damage) {
        this.damage = damage;
    }

    public int getDespawn() {
        return despawn;
    }

    public void setDespawn(int despawn) {
        this.despawn = despawn;
    }
}
